<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Visitante extends CI_Controller {
    public function __construct(){
        parent::__construct();
            $this->session->set_userdata('componente','visitante');
            $this->load->model('Reserva_Model');
            $this->load->helper('date');
    }
    public function index(){
        if(!$this->session->userdata('componente')){
            echo "Componente indefinido!";
        }
        else{
            $componente = $this->session->userdata('componente').'_view';  
            $this->load->view($componente,$componente);
        }
    }
    public function json(){
        foreach ($this->Reserva_Model->reservasVisita() as $row){
            $idevento = $row->idreserva;
            $status = $row->status_idstatus;
            $start = $row->dtinicial;
            $end = $row->dtfinal;
            $token = $row->token;
            switch($status){
               case '1' : 
                   $cor    = 'green';
                   $text   = 'white';
                   $title  = 'Livre';
               break;
               case '2' : 
                   $cor    = 'orange';
                   $text   = 'white';
                   $title  = 'Agendado';
               break;
               case '3' : 
                   $cor    = 'red';
                   $text   = 'white';
                   $title  = 'Reservado';
               break;
            }
            $resultado[] = array(
                'id'    =>$idevento,
                'title' =>$title,
                'start' =>$start,
                'end'   =>$end,
                'color' =>$cor,
                'textColor' =>$text,
            );
        }
        echo json_encode($resultado);        
    }
}